<?php

class Nld_Cache
{
	protected static $_tables = array();
	
	static function value($dir, $time=60)
	{
		is_dir($dir) or mkdir($dir, 0755, true);
		return Zend_Cache::factory('Core', 'File', array('lifetime' => $time, 'automatic_serialization' => true), array('cache_dir' => $dir));
		
		$cache = Zend_Cache::factory('Core', 'File', array('lifetime' => $time, 'automatic_serialization' => true), array('cache_dir' => $dir));
		if(!($result = $cache->load($key)))
		{
			$cache->save($val, $key);
		}
		return $result;
	}
	static function query($select, $dir, $time=60)
	{
		$key = md5($select);
		is_dir($dir) or mkdir($dir, 0755, true);
		$cache = Zend_Cache::factory('Core', 'File', array('lifetime' => $time, 'automatic_serialization' => true), array('cache_dir' => $dir));
		if(!($result = $cache->load($key)))
		{
			$result = $select->query()->fetchAll();
			$cache->save($result, $key);
		}
		return $result;
	}
	static function output($dir, $time=60)
	{
		is_dir($dir) or mkdir($dir, 0755, true);
		return Zend_Cache::factory('Output', 'File', array('lifetime' => $time, 'automatic_serialization' => true), array('cache_dir' => $dir));
	}
}